package com.example.listvwork;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class GoodsADapter  extends ArrayAdapter<Goods> {
    private int resource;

    public GoodsADapter(@NonNull Context context, int resource, @NonNull List<Goods> objects) {
        super(context, resource, objects);
        this.resource = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view= LayoutInflater.from(getContext()).inflate(resource,parent,false);
        Goods goods=getItem(position);

        ImageView imageView=view.findViewById(R.id.iv);
        imageView.setImageResource(goods.getImageId());

        TextView name=view.findViewById(R.id.tv_name);
        name.setText(goods.getName());

        TextView price=view.findViewById(R.id.tv_price);
        price.setText(goods.getPrice());
        return view;
    }
}
